﻿namespace NodeBasedSkillEditor
{
    public class Value_Boolean : AValue
    {
        public override EValueType ValueType { get { return EValueType.Boolean; } }

        public bool Value;

        public Value_Boolean(bool y)
        {
            Value = y;
        }

        public Value_Boolean(BooleanPort portData)
        {
            Value = portData.Value;
        }

        public override AValue Clone()
        {
            return new Value_Boolean(Value);
        }

        public override (bool, bool) ToBoolean()
        {
            return (true, Value);
        }

        public override bool SetBoolean(bool v)
        {
            Value = v;
            return true;
        }

        public override (bool, int) ToInteger()
        {
            return (true, Value ? 1 : 0);
        }

        public override bool SetInteger(int v)
        {
            Value = v != 0;
            return true;
        }

        public override (bool, float) ToScalar()
        {
            return (true, Value ? 1 : 0);
        }

        public override bool SetScalar(float v)
        {
            Value = v != 0;
            return true;
        }

        public override void Reset()
        {
            Value = false;
        }

        public override void Negative()
        {
            Value = !Value;
        }

        public override void And(AValue x)
        {
            var v = x.ToBoolean();
            if (v.Item1)
            {
                Value = Value && v.Item2;
            }
        }

        public override void Or(AValue x)
        {
            var v = x.ToBoolean();
            if (v.Item1)
            {
                Value = Value || v.Item2;
            }
        }

        public override void XOR(AValue x)
        {
            var v = x.ToBoolean();
            if (v.Item1)
            {
                Value = v.Item2 != Value;
            }
        }

        public override void XNOR(AValue x)
        {
            var v = x.ToBoolean();
            if (v.Item1)
            {
                Value = v.Item2 == Value;
            }
        }

        public override bool EqualsValue(AValue x)
        {
            var v = x.ToBoolean();
            if (v.Item1)
            {
                return Value == v.Item2;
            }
            else return false;
        }

        public override string ToString()
        {
            return Value.ToString();
        }
    }
}
